package org.dtrd.modules.doctor.entity.bean;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dtrd.common.util.DateUtils;
import org.dtrd.common.util.StringUtil;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.doctor.entity.po.DtrdEntRdDoctor;

import javax.validation.constraints.NotBlank;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;

/**
 * <p>
 * 医生表
 * </p>
 *
 * @author QR
 * @since 2021-11-30 16:22:19
 */
@Data
@NoArgsConstructor
@ApiModel(value = "医生信息数据传输对象")
public class DoctorInfo {

    private Integer dataId;

    @NotBlank
    @ApiModelProperty(value = "手机号码", required = true)
    private String doctorsMobile;

    @NotBlank
    @ApiModelProperty(value = "姓名", required = true)
    private String doctorsName;

    @ApiModelProperty("年龄")
    private Integer doctorsAge;

    @ApiModelProperty(value = "出生日期")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date doctorsBirthday;

    @ApiModelProperty(value = "性别")
    private Integer doctorsSex;

    @ApiModelProperty("身份证号码")
    private String doctorsIdCard;

    @ApiModelProperty("所属省份Id")
    private Integer doctorsProvinceId;

    @ApiModelProperty(value = "所属城市Id")
    private Integer doctorsCityId;
    @ApiModelProperty(value = "工作所在地")
    private String doctorsCity;

    @ApiModelProperty("所属区Id")
    private Integer doctorsDistrictId;

    @ApiModelProperty("头像图片地址")
    private String doctorsImg;

    @ApiModelProperty(value = "所属医院", required = true)
    private String doctorsHospital;
    @ApiModelProperty(value = "所属医院编号", required = true)
    private String doctorsHospitalId;

    @ApiModelProperty(value = "科室", required = true)
    private String doctorsDepartment;

    @ApiModelProperty("所属部门Id")
    private String doctorsDepartmentId;

    @ApiModelProperty("职称Id")
    private String doctorsLevelId;

    @ApiModelProperty(value = "职称", required = true)
    private String doctorsLevel;

    @ApiModelProperty(value = "执业证书图片地址")
    private String doctorsCertificate;

    @ApiModelProperty(value = "医师资格证图片地址")
    private String doctorsWorkPermits;

    @ApiModelProperty(value = "职称证书图片地址")
    private String doctorsProfessionImg;

    @ApiModelProperty(value = "胸牌")
    private String doctorsWorkCard;

    @ApiModelProperty(value = "职业专长")
    private String doctorsSpecialSkill;

    @ApiModelProperty(value = "工作经历")
    private String doctorsWorkExperience;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM", timezone = "GMT+8")
    @ApiModelProperty(value = "从业医生的开始时间")
    private Date doctorsTimeWork;

    @ApiModelProperty(value = "执业时间")
    private Integer workingTime;

    @ApiModelProperty("加入医生团队二维码")
    private String qrcodeAddTeam;

    @ApiModelProperty("添加患者二维码")
    private String qrcodeAddPatient;

    @ApiModelProperty(value = "医生类型：1-医助,2-营养师,3-健康管理师,4-心理咨询师,5-运动康复师,6-医生", required = true)
    private Integer doctorsType;

    /**
     * 钱包提现密码
     */
    private String doctorsWalletPassword;

    @ApiModelProperty(value = "认证状态", notes = "0-未认证，1-已认证 2-待认证")
    private Integer identifyStatus;

    @ApiModelProperty(value = "医生标签", notes = "逗号拼接")
    private String doctorsTag;
    @ApiModelProperty(value = "医生标签-中文")
    private ArrayList doctorsTagName;

    @ApiModelProperty(value = "审核状态", notes = "审核状态：0-不通过，1-通过")
    private Integer doctorsIsverify;

    @ApiModelProperty(value = "审核不通过原因")
    private String remark;

    /**
     * 认证情况:1-已冻结,0-未冻结
     */
    @ApiModelProperty("账号冻结情况")
    private Integer doctorsStatus;

    @ApiModelProperty(value = "审核时间")
    private Date doctorsVerifyTime;

    @ApiModelProperty(value = "登录密码", hidden = true)
    private String doctorsPassword;

    @ApiModelProperty(value = "团队id", hidden = true)
    private Integer teamId;

    @ApiModelProperty(value = "团队名称", hidden = true)
    private String teamName;

    public DoctorInfo(DtrdEntRdDoctor doctor) {
        parseFromPO(doctor);
    }

    public DoctorInfo parseFromPO(DtrdEntRdDoctor po) {
        // 二维码
        qrcodeAddTeam = po.getQrcodeAddTeam();
        qrcodeAddPatient = po.getQrcodeAddPatient();
        dataId = po.getDataId();
        doctorsMobile = po.getDoctorsMobile();
        doctorsPassword = po.getDoctorsPassword();
        doctorsName = po.getDoctorsName();
        doctorsBirthday = po.getDoctorsBirthday();
        if (doctorsBirthday != null) {
            doctorsAge = DateUtil.age(po.getDoctorsBirthday(), null);
        }
        doctorsSex = po.getDoctorsSex();
        doctorsIdCard = po.getDoctorsIdCard();
        doctorsProvinceId = po.getDoctorsProvinceId();
        doctorsCityId = po.getDoctorsCityId();
        doctorsDistrictId = po.getDoctorsDistrictId();
        doctorsImg = po.getDoctorsImg();
        // 医院
        this.doctorsHospital = po.getDoctorsHospital();
        doctorsHospitalId = po.getDoctorsHospitalId();
        // 部门
        doctorsDepartment = po.getDoctorsDepartment();
        if (po.getDoctorsTimeWork() != null) {
            doctorsTimeWork = po.getDoctorsTimeWork();
            workingTime = DateUtils.getDiffYear(po.getDoctorsTimeWork(), new Date());
        }
        // 职称
        doctorsLevel = po.getDoctorsLevel();
        doctorsSpecialSkill = po.getDoctorsSpecialSkill();
        doctorsWorkExperience = po.getDoctorsWorkExperience();
        doctorsType = po.getDoctorsType();
        identifyStatus = StringUtil.StrTrimInt(po.getDoctorsIsverify());
        doctorsCertificate = po.getDoctorsCertificate();
        doctorsWorkPermits = po.getDoctorsWorkPermits();
        doctorsProfessionImg = po.getDoctorsProfessionImg();
        doctorsWorkCard = po.getDoctorsWorkCard();
        doctorsTag = po.getDoctorsTag();
        if (po.getDoctorsTag() != null) {
            ArrayList<String> tagName = new ArrayList<>();
            String[] keyArr = doctorsTag.split(",");
            for (String item : keyArr) {
                tagName.add(Constant.DoctorTags.valueOf(Integer.valueOf(item)).getName());
            }
            doctorsTagName = tagName;
        }
        // 医生审核
        doctorsIsverify = po.getDoctorsIsverify();
        remark = po.getRemark();
        if (po.getDoctorsVerifyTime() != null) {
            try {
                doctorsVerifyTime = DateUtils.parseDate(po.getDoctorsVerifyTime(), DateUtils.date_sdf.get().toPattern());
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        teamId = po.getTeamId();
        return this;
    }


}
